package guiobjects;

import java.awt.Color;
import java.util.Scanner;

/**
 * Draws a rectangle.
 * 
 * @author Trevor Terris
 *
 */
public class Rectangle implements IPaintedObject
{
	private double x1;
	private double y1;
	private double x2;
	private double y2;
	private Color myColor = Color.black;
	public void parseText(String input)
	{
		Scanner s = new Scanner(input);
		x1 = s.nextDouble();
		y1 = s.nextDouble();
		x2 = s.nextDouble();
		y2 = s.nextDouble();
		if (s.hasNextInt())
		{
			myColor = new Color(s.nextInt(), s.nextInt(), s.nextInt());
		}
	}
	public void drawObject(java.awt.Graphics pen, int screenWidth, int screenHeight, int offset)
	{
		double startx = Math.min(x1, x2);
		double starty = Math.min(y1, y2);
		double xDiff = Math.abs(x1 - x2);
		double yDiff = Math.abs(y1 - y2);
		pen.setColor(myColor);
		pen.fillRect((int)(startx * screenWidth) + offset, (int)(starty * screenHeight), (int)(xDiff * screenWidth), (int)(yDiff * screenHeight));
	}	
	public String getSVGData(int width, int offset, int total)
	{
		double rectWidth = (Math.abs(x2 - x1) * (double)width) * 100.0 / (double) total;
		double rectHeight = Math.abs(y2 - y1) * 100.0;
		double rectX = (Math.min(x1, x2) * (double) width + (double)offset) * 100.0 / (double) total;
		double rectY = Math.min(y1, y1) * 100.0;
		
		String output = "<rect x=\""+rectX+"%\" y=\""+rectY+"%\" width=\""+rectWidth+"%\" height=\""+rectHeight
						+"%\" style=\"fill:rgb("+myColor.getRed()+","+myColor.getGreen()+","+myColor.getBlue()+
						");\"/>";
		return output;
	}
}
